<?php
/**
 * Created by PhpStorm.
 * User: wei
 * Date: 2016/2/26
 * Time: 11:06
 */
namespace Api\Controller;
use Think\Controller;
class AuthenticationController extends BaseController {
    public function auth(){
        //解决跨域
        echoHeader();
        $ID_num=I('post.number');        //身份证号码
        $ID_name=I('post.name');        //姓名
        $user_id=I('post.user_id');
        $key=I('post.key');
        $pic_psitive=I('post.psitive');    //正面
        $pic_other_side=I('post.verso');       //反面
        $pic_hold=I('post.hold');         //手持身份证

        if(empty($pic_hold) || empty($pic_other_side) || empty($pic_psitive) || empty($key) || empty($user_id) || empty($ID_num) || empty($ID_name)){
            $data = array('err_code' => 1001, 'err_msg' => '缺少参数');
            $this->ajaxReturn($data, 'JSON');
        }


        $userInfo=M('user_real_info');
        $u=M('user')->where("user_id=$user_id")->find();

        if($u['is_real']==2){
            $data = array('err_code' => 1007, 'err_msg' => '已提交');
            $this->ajaxReturn($data, 'JSON');
        }

        $map['pic_psitive']=$pic_psitive;
        $map['pic_other_side']=$pic_other_side;
        $map['pic_hold']=$pic_hold;
        $map['id_name']=$ID_name;
        $map['id_num']=$ID_num;
        $map['user_id']=$user_id;
        $map['add_time']=time();
        $dewhere['user_id']=$user_id;
        $userInfo->where($dewhere)->delete();
        if($userInfo->add($map)===false){
            $data = array('err_code' => 403, 'err_msg' => '发送失败');
            $this->ajaxReturn($data, 'JSON');
        }else{
            $where['user_id']=$user_id;
            $map['is_real']=2;
            M('user')->where($where)->save($map);

             //师傅实名时插入维修模式数据 add by laiwenhua 
            $model = M("UserMode");
            $modeMap['user_id'] = $user_id;
            $modeMap['mode_cate'] = 1;
            $mode = $model->where($modeMap)->find();
            if(!$mode){
                $modeMap['mode_order'] = "1,2";
                $modeMap['mode_charging'] = "1,2,3";
                $modeMap['mode_traffic'] = 1;
                $model->add($modeMap);
            }
            $data = array('err_code' => 200, 'err_msg' => '发送成功');
            $this->ajaxReturn($data, 'JSON');
        }


    }


    public function treelist(){
        $cate = M()->query('SELECT id,pid,title AS name FROM '.C('DB_PREFIX').'menu ORDER BY sort_order ASC');

        $list =list_to_tree($cate);
       // $list = json_encode($list);
        $data = array('err_code' => 1001, 'err_msg' => $list);
        $this->ajaxReturn($data, 'JSON');
    }

}
